﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HA.Data
{
    [Serializable]
    public class Grid3dCollecion
    {
        public Grid3dCollecion()
        {
            this._grids = new List<Grid3d>();
 
        }

        List<Grid3d> _grids;

        public List<Grid3d> Grids
        {
            get { return _grids; }
           
        }

        public Grid3d MainGrid
        {
            get
            {
                if (this._grids.Count > 0)
                {
                    return this._grids[0];

                }
                else
                {
                    return null;
                }
            }

            set {

                if (this._grids.Count > 0)
                {
                    this._grids[0] = value;

                    if (this.CollectionChanged != null)
                    {
                        this.CollectionChanged(this, new CollecionChangedEventArgs(this._grids[0], CollectionChangedType.REPLACE));

                    }


                }

                else
                {
                    this.Add(value);

                   
                }
            }
        }


         



        [field: NonSerialized]
        public event EventHandler<CollecionChangedEventArgs> CollectionChanged;

        public void Add(Grid3d data)
        {
            this.Grids.Add(data);

            if (this.CollectionChanged != null)
            {
                this.CollectionChanged(this, new CollecionChangedEventArgs(data, CollectionChangedType.ADD));

            }

        }

        public void Remove(Grid3d data)
        {
            if (this.Grids.Contains(data))
            {
                this.Grids.Remove(data);

                if (this.CollectionChanged != null)
                {
                    this.CollectionChanged(this, new CollecionChangedEventArgs(data, CollectionChangedType.REMOVE));

                }

            }
        }


    }
}
